<template>
  <view class="container">
    <view class="tab-box">
      <view :class="['tab', status == 0 ? 'active' : '']" @click="changeTab(0)">全部</view>
      <view :class="['tab', status == 1 ? 'active' : '']" @click="changeTab(1)">待审核</view>
      <view :class="['tab', status == 2 ? 'active' : '']" @click="changeTab(2)">已通过</view>
      <view :class="['tab', status == -1 ? 'active' : '']" @click="changeTab(-1)">未通过</view>
    </view>

    <scroll-view scroll-y @scrolltolower="loadMore" class="list">
      <navigator hover-class="none" :url="'/pages/project_detail/project_detail?id='+item.id" class="box" v-for="(item, index) in list" :key="index">
        <view :class="['status', item.status == 1 ? 'dsh' : (item.status == 2 ? 'ytg' : 'wtg')]">{{ item.status_desc }}</view>
        <view class="row">
          <view class="text">项目名称：</view>
          <view class="info">{{ item.name }}</view>
        </view>
        <view class="row">
          <view class="text">联系人：</view>
          <view class="info">{{ item.head_name }}，{{ item.head_mobile }}</view>
        </view>
        <view class="row">
          <view class="text">岗位：</view>
          <view class="info">{{ item.post_list[0].name }}</view>
        </view>
        <view class="row">
          <view class="text">体验时间：</view>
          <view class="info">{{ item.post_list[0].time }}</view>
        </view>
        <view class="row">
          <view class="text">辅导员：</view>
          <view class="info">{{ item.post_list[0].counsellor_name }}、{{ item.post_list[0].counsellor_unit }}</view>
        </view>
        <view class="btn-box" v-if="item.status == -1">
          <view class="btn" @click.stop="lookRefuseReason(index)">查看原因</view>
        </view>
        <view class="btn-box" v-if="item.status == 2">
          <view @click.stop="href" :data-url="'/pages/apply_subsidy/apply_subsidy?project_id=' + item.id" class="bt-btn">补贴申请</view>
          <view @click.stop="href" :data-url="'/pages/join_status/join_status?project_id=' + item.id" class="btn">已报名：{{ item.join_count }}</view>
        </view>
      </navigator>
    </scroll-view>

  </view>
</template>

<script>
export default {
  data() {
    return {
      status: 0,
      list: [],
      page: 1,
      pagesize: 10,
    }
  },

  onLoad() {
    this.userProjectList();
  },

  methods: {
    changeTab: function (status) {
      this.page = 1;
      this.status = status;
      this.userProjectList();
    },

    href: function (e) {
      var url = e.currentTarget.dataset.url;
      uni.navigateTo({
        url: url
      })
    },

    lookRefuseReason: function (index) {
      /*uni.showModal({
       title: '未通过原因',
       content: this.list[index].refuse_reason,
       cancelColor: '#32a4ff',
       cancelText: '我知道了',
       confirmColor: '#32a4ff',
       confirmText: '修改申请',
       success: res => {
       if (res.confirm) {
       uni.redirectTo({
       url: '/pages/apply_project/apply_project?id=' + this.list[index].id
       })
       }
       }
       })*/
      uni.showModal({
        title: '未通过原因',
        content: this.list[index].refuse_reason,
        showCancel: false,
        confirmColor: '#32a4ff',
        confirmText: '我知道了',
      })
    },

    loadMore: function () {
      this.userProjectList(this.page + 1)
    },

    // 项目管理列表
    userProjectList: function (incPage = 0) {
      var page = incPage ? incPage : this.page;

      uni.showLoading({
        title: '数据加载中...',
        mask: true
      })

      this.$http.post('/index/Api/userProjectList', {
        user_id: uni.getStorageSync('user_id'),
        status: this.status,
        page: page,
        pagesize: this.pagesize
      }).then((res) => {
        if (res.data.result == 1) {
          if (page == 1) {
            this.list = res.data.data;
          } else {
            // 加载更多
            var list = this.list;

            for (var i = 0; i < res.data.data.length; i++) {
              list.push(res.data.data[i]);
            }

            this.list = list;
            this.page = page;
          }

          setTimeout(() => {
            uni.hideLoading();
          }, 500)
        } else {
          if (page == 1) this.list = [];

          uni.hideLoading();
          this.$common.doErrorResult(res);
        }
      })
    },
  }
}
</script>

<style lang="scss">
.container {
  padding: 20rpx;
  background: #f5f5f5;

  .tab-box {
    display: flex;
    width: 70%;
    justify-content: space-between;
    margin-bottom: 20rpx;
    position: fixed;
    top: 20rpx;
    left: 20rpx;
    z-index: 99;

    .tab {
      text-align: center;
      flex: 1;
      color: #8C8888;
    }

    .active {
      color: #B574FF;
    }
  }

  .list {
    margin-top: 60rpx;
    height: calc(100vh - 120rpx);

    .box {
      display: flex;
      flex-direction: column;
      padding: 16rpx 24rpx;
      margin-bottom: 20rpx;
      background: #fff;
      border-radius: 20rpx;

      .status {
        text-align: right;
      }

      .dsh {
        color: #55B4FF;
      }

      .ytg {
        color: #B574FF;
      }

      .wtg {
        color: #FF7155;
      }

      .title {
        font-size: 32rpx;
        font-weight: bold;
      }

      .row {
        display: flex;
        align-items: center;
        margin-top: 14rpx;

        .text {
          font-size: 28rpx;
          width: 140rpx;
        }

        .info {
          font-size: 24rpx;
          color: #3D3D3D;
        }
      }

      .btn-box {
        display: flex;
        justify-content: flex-end;
        margin-top: 20rpx;

        .btn {
          font-size: 24rpx;
          color: #FFF;
          background: #32A4FF;
          //width: 120rpx;
          height: 60rpx;
          line-height: 60rpx;
          padding: 0 24rpx;
          border-radius: 50rpx;
          text-align: center;
          margin-left: 40rpx;
        }

        .bt-btn {
          font-size: 24rpx;
          color: #32A4FF;
          background: #FFF;
          width: 120rpx;
          height: 60rpx;
          line-height: 60rpx;
          padding: 0 24rpx;
          border-radius: 50rpx;
          text-align: center;
          border: 1rpx solid #32A4FF;
        }

      }

    }
  }

}

</style>
